package com.dc.service.impl;

import com.dc.base.em.ErrorMessageEnum;
import com.dc.base.vo.BaseModel;
import com.dc.base.vo.BusinessException;
import com.dc.dao.OperationLogDao;
import com.dc.model.OperationLog;
import com.dc.service.OperationLogService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class OperationLogServiceImpl implements OperationLogService {
    @Autowired
    OperationLogDao operationLogDao;
    public BaseModel selectPageOperationLog(Integer curr_page, Integer page_size, BaseModel baseModel, String user_name,String user_account) throws Exception {
        // 启动分页
        PageHelper.startPage(curr_page,page_size);
        List<OperationLog> operationLogList=operationLogDao.selectPageOperationLog(user_name,user_account);
        PageInfo pageInfo =new PageInfo(operationLogList,5);
        baseModel.setResultCode(0);
        baseModel.setMessage("分页查询登录日志成功！");
        baseModel.setData(pageInfo);
        return baseModel;
    }

    public BaseModel addOperationLog(OperationLog operationLog, BaseModel baseModel) throws Exception {
        //调用新增用户的dao
        Integer result=operationLogDao.insertOperationLog(operationLog);
        if(result<1){
            throw new BusinessException(ErrorMessageEnum.ADD_USER_ERROR);
        }
        baseModel.setResultCode(0);
        baseModel.setMessage("新增登录日志成功！");
        return baseModel;
    }
}
